clear all;

cd ..; cd ..; cd ..;
load('code_main_model\6_implied_w_r\computation_results\data.mat','V_ad_ini','V_noad_ini','gtheta_ini',...
    'nb','ntheta','nz','gridb','gridtheta','gridz','nb_pdf','ntheta_pdf','gridb_pdf','gridtheta_pdf');
cd 'code_figure_table\OA\Figure OA6';

withdraw(1:nmkt,1:nz,1:nb,1:ntheta)=0;
deposit(1:nmkt,1:nz,1:nb,1:ntheta)=0;

for i_mkt=1:nmkt
    for i_b=1:nb
        for i_z=1:nz
            for i_theta=1:ntheta
                if V_ad_ini(i_mkt,i_z,i_b,i_theta) >= V_noad_ini(i_mkt,i_z,i_b,i_theta)

                    b=gridb(i_b);
                    theta=gridtheta(i_theta);
                    m=b*theta;
                    a=b-m;
                    theta_prime=gtheta_ini(i_mkt,i_z,i_b,i_theta);

                    if (theta_prime > theta)
                        withdraw(i_mkt,i_z,i_b,i_theta)=1;
                    else
                        deposit(i_mkt,i_z,i_b,i_theta)=1;
                    end
                end
            end
        end
    end
end

save('withdraw_deposit.mat','withdraw','deposit','gridb','gridtheta','gridz','nb','ntheta','nz','nmkt')